IF exists(SELECT * FROM dbo.sysobjects WHERE name='WEB_alleKlassen' AND xtype='P') 
BEGIN
	DROP PROCEDURE WEB_alleKlassen
END
GO

CREATE procedure WEB_alleKlassen
as
set nocount on
select 0 as volgNr,'' as klas,0 as klasNr,'<?xml version=''1.0'' encoding="ISO-8859-1" ?>' as tekst
union
select 1,'',0,'<opdrachten naamcode="Alle klassen">'
union
select distinct 2,upper(l.klas),0,
		'<groep><klas>' + upper(rtrim(isNull(l.klas,''))) + '</klas>'
from leerlingen..leerlingen as l 
union 
select 2,upper(l.klas),klasNr,'<lln iNr="' + inschrijvingsNr 
		+ '" klasNr="' + convert(varchar(5),klasNr) + '">'  
		+ isnull(voornaam,'') + ' ' + isnull(achternaam,'') + '</lln>'
from leerlingen..leerlingen as l
union
select 2,upper(l.klas),999,'</groep>'
from leerlingen..leerlingen as l
union
select 3,'',0,'</opdrachten>'
order by volgNr,klas,klasNr